#!/bin/bash

# 设置NDK路径
platform=$1
if [[ $1 = "x86" ]]; then
arch=i686
abi=x86
elif [[ $1 = "x64" ]]; then
arch=x86_64
abi=x86_64
elif [[ $1 = "arm" ]]; then
arch=armv7a
abi=armeabi-v7a
else
platform=arm64
arch=aarch64
abi=arm64-v8a
fi

newbuild=$2
echo build $platform $arch

export NDK=$NDK_HOME
export CMAKE=$CMAKE_HOME/bin
export BLD=`pwd`/install_$platform
export SRC=`pwd`/src
export HOST=$arch-linux-androideabi
export PLATFORM=$arch-linux-android
export API=28
export ANDROID_NDK_HOME=$NDK
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64

export AR=$TOOLCHAIN/bin/llvm-ar
if [[ $1 = "arm" ]]; then
export CC=$TOOLCHAIN/bin/${PLATFORM}eabi${API}-clang
export CXX=$TOOLCHAIN/bin/${PLATFORM}eabi${API}-clang++
else
export CC=$TOOLCHAIN/bin/$PLATFORM$API-clang
export CXX=$TOOLCHAIN/bin/$PLATFORM$API-clang++
fi
export AS=$CC
export LD=$TOOLCHAIN/bin/ld
export RANLIB=$TOOLCHAIN/bin/llvm-ranlib
export STRIP=$TOOLCHAIN/bin/llvm-strip

# 设置目标平台和架构
export PLATFORM=android-21
export ARCH=aarch64

# 设置OpenSSH源代码路径
export OPENSSH_SRC=openssh-9.0p1

# 设置编译参数
export CFLAGS="-fPIE -pie"
export LDFLAGS="-fPIE -pie"

# 编译OpenSSH
cd $OPENSSH_SRC
mkdir build
cd build
../configure --host=$ARCH-linux-androideabi --with-ssl-dir=../../../src/openssl-1.1.1t --prefix=$BLD
make
make install

